﻿//选中的邮件ID
var pm_IDs="";
//更新状态标记
var isRead;
//4全选、1取消全选
function selMail(val){
	if(val==0||val==1){
		selMailOp(0);
		setDelState();
	}
	else if(val==2){
		selMailOp(2);
	}
	 else if(val==3){
		selMailOp(3);
	}
	 else if(val==4){
		selMailOp(1);
		setDelState();
	}
}
//
function selMailOp(val)
{
    var elments = $("MailListID").getElementsByTagName("input");
    for (var i = 0; i < elments.length; i++)
    {
        if(elments[i].type=="checkbox")
        {
            switch(val)
            {
                case 0:
                    elments[i].checked=false;
                    break;
                case 1:
                    elments[i].checked=true;
                    break;
                case 2:
                    if(elments[i].value=="1")
                        elments[i].checked=true;
                    else
                        elments[i].checked=false;
                    break;
                case 3:
                    if(elments[i].value=="0")
                        elments[i].checked=true;
                    else
                        elments[i].checked=false;
                    break;
            }
        }
    }

}
//设置删除状态
function setDelState()
{
    var readflag=false;
    var elments = $("MailListID").getElementsByTagName("input");
    for (var i = 0; i < elments.length; i++)
    {
        if(elments[i].type=="checkbox" && elments[i].checked)
        {
            readflag=true;
            break;           
        }        
    }
    if(readflag)
    {
        $("showDELDiv").style.display="";
        $("hideDelDiv").style.display="none";
    }
    else
    {
        $("showDELDiv").style.display="none";
        $("hideDelDiv").style.display="";
    }
}

//更新阅读状态
function MarkRead(val)
{    
    isRead=val;
    pm_IDs="";
    var elments = $("MailListID").getElementsByTagName("input");
    for (var i = 0; i < elments.length; i++)
    {
        if(elments[i].type=="checkbox" && elments[i].checked)
        {
            pm_IDs += (elments[i].id).substring(3,elments[i].id.length) +",";
        }
    }
    if(pm_IDs.length>0) pm_IDs = pm_IDs.substring(0,pm_IDs.length-1);
    //alert(pm_IDs);
    showProgressBar(true);
    WebServices.User.Mail.UpdateIsRead(isRead,pm_IDs,onssMR)
}
//状态更新后初始化
function onssMR(result)
{
    if(result.State)
    {
        $("MessagesBox").style.display="";
        $("MessageText").innerHTML=mesText1;
        var pm_id=pm_IDs.split(",");
        for(var i=pm_id.length-1; i>=0; i--)
        {
            $("ck_"+pm_id[i]).value=(isRead?"1":"0");
            $("ck_"+pm_id[i]).checked=false;
            $("tbID_"+pm_id[i]).className=(isRead?"Read":"noRead");
            $("img_"+pm_id[i]).src=(isRead?"/Images/icon_mail_read.gif":"/Images/icon_mail_none.gif");
        }
        setReadBtt();
    }
    else
    {
        $("MessagesBox").style.display="";
        $("MessageText").innerHTML=mesText2;
    }
    showProgressBar(false);
}
function DelPM(id)
{
        var pmids = "";
        var elments = $("MailListID").getElementsByTagName("input");
        for (var i = 0; i < elments.length; i++)
        {
            if(elments[i].type=="checkbox" && elments[i].checked)
            {
                pmids += (elments[i].id).substring(3,elments[i].id.length) +",";
            }
        }
        if(pmids.length==0&&id==-1)return;
        showProgressBar(true);
    showProgressBar(false,true);
    $("$divIput$").style.display = "none";
    var title = C1008;
    var body="";
    body="<div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"DelPM1('"+id+"')\" />&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";
    var obj = {}
    $ShowMessageBox$(title,body,obj,webFailure,300);
    showProgressBar(false);    
}
//删除邮件
function DelPM1(val)
{
    if(val==-1)
    {
        var pmids = "";
        var elments = $("MailListID").getElementsByTagName("input");
        for (var i = 0; i < elments.length; i++)
        {
            if(elments[i].type=="checkbox" && elments[i].checked)
            {
                pmids += (elments[i].id).substring(3,elments[i].id.length) +",";
            }
        }
        if(pmids.length>0) pmids = pmids.substring(0,pmids.length-1);
        $("delMID").value=pmids;
        $("Form1").action = "/Mail/Inbox.htm";
        $("Form1").submit();
    }
    else
    {
        $("delMID").value=val;
        $("Form1").action = "/Mail/Inbox.htm";
        $("Form1").submit();
    }
}
function webFailure()
{
    $EndMessageBox$();
}